package org.bookie.mtest;


import static org.testng.Assert.assertEquals;

import java.io.IOException;
import java.net.MalformedURLException;

import org.bookie.mtest.framework.Application;
import org.bookie.mtest.framework.GroupsPage;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import com.meterware.httpunit.WebTable;

@Test
public class GroupsPageTest {
	
	public void testGroupTable() throws MalformedURLException, SAXException, IOException{
		GroupsPage page = createPage();
		
		WebTable table = page.getGroupsTable();
		assertEquals(table.getColumnCount(), 2);
		assertEquals(table.getRowCount(), 4+2);
		assertEquals(table.getCellAsText(1, 0), "Simpson family");
		
		//now test sort links
		page.clickOnLinkWithId("linkColumn");
		table = page.getGroupsTable();
		assertEquals(table.getCellAsText(1, 0), "Bouvier family");
		
		page.clickOnLinkWithId("linkColumn_0");
		page.clickOnLinkWithId("linkColumn_0");
		table = page.getGroupsTable();
		assertEquals(table.getCellAsText(1, 0), "Simpson family");
	}
	
	private GroupsPage createPage() throws MalformedURLException, SAXException, IOException{
		Application application = new Application();
		GroupsPage page = application.start().getGroupsPage();
		page.assertPageTitle("Groups");
		return page;
	}
}
